#include"udp_socket.hpp"

int main(int argc,char* argv[])
{
  if(argc!=3)
  {
    std::cout<<"./udp_clinet 192.168.2.2 10000\n";
    return -1;
  }
  std::string ip = argv[1];
  uint16_t port = std::stoi(argv[2]);

  UdpSocket clinet_sock;
  //1. 创建套接字
  clinet_sock.Socket();

  while(1)
  {
    //2. 发送数据
    std::string data;
    std::cout<<"clinet say: ";
    fflush(stdout);
    std::cin>>data;
    assert(clinet_sock.Send(data,ip,port) == true);

    //3. 接收数据
    data.clear();
    assert(clinet_sock.Recvfrom(&data) == true);
    std::cout<<"server say: "<<data<<std::endl;
  }

  //4. 关闭套接字
  clinet_sock.Close();
  return 0;
}
